﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;
using System.Web.UI.HtmlControls;

namespace CoolERP_Web.User
{
    public partial class CS_YS_Query : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AspNetPager1.PageSize = GridView1.PageSize;
                BindData();
            }
        }
        private void BindData()
        {
            List<CS_YS_Ex> listEx = new List<CS_YS_Ex>();

            CS_YSLXBLL yslxB = new CS_YSLXBLL();
            List<CS_YSLX> yslxList = yslxB.GetAll();

            int RecordCount = 0;
            using (CS_YSBLL ysB = new CS_YSBLL())
            {
                List<CS_YS> list = ysB.GetPagerList(null, "YSLXBH,BH", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out RecordCount);
                this.AspNetPager1.RecordCount = RecordCount;

                CS_YS_Ex ce = null;
                foreach (CS_YS c in list)
                {
                    ce = new CS_YS_Ex();
                    ce.YSLXBH = c.YSLXBH;
                    CS_YSLX yslx = yslxList.Find(delegate(CS_YSLX p) { return p.BH == c.YSLXBH; });
                    ce.YSLXMC = yslx.MC;
                    ce.BH = c.BH;
                    ce.MC = c.MC;
                    listEx.Add(ce);
                }
                this.GridView1.DataSource = listEx;
                this.GridView1.DataBind();
                this.AspNetPager1.Visible = RecordCount > 0;
                panMsg.Visible = !this.AspNetPager1.Visible;
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected class CS_YS_Ex
        {
            public string YSLXBH { get; set; }
            public string YSLXMC { get; set; }
            public string BH { get; set; }
            public string MC { get; set; }
        }
    }
}